import random


class RandomizedSet:
    def __init__(self):
        self.vals = []
        self.pois = {}

    def insert(self, val):
        if val not in self.pois:
            self.vals.append(val)
            self.pois[val] = len(self.vals) - 1
            return True

        return False

    def remove(self, val):
        if val in self.pois:
            idx = self.pois[val]
            last = self.vals[-1]
            self.vals[idx] = last
            self.pois[last] = idx
            self.vals.pop()
            del self.pois[val]
            return True

        return False

    def getRandom(self):
        return random.choice(self.vals)


if __name__ == "__main__":
    randomSet = RandomizedSet()
    print(randomSet.insert(2))
    print(randomSet.insert(3))
    print(randomSet.insert(4))
    print(randomSet.insert(5))
    print(randomSet.insert(6))

    print(randomSet.remove(4))
    print(randomSet.remove(7))
    print(randomSet.getRandom())
